#include <Editor/StdAfx.h>
#include "ViewPanel3D.h"
#include "MainFrame.h"

BEGIN_EVENT_TABLE(ViewPanel3D, wxPanel)
	EVT_SIZE(OnSize)
	EVT_MOUSE_EVENTS(OnMouse)
	EVT_KEY_DOWN(OnKeyDown)
	EVT_KEY_UP(OnKeyUp)
	EVT_SET_FOCUS(OnSetFocus)
	EVT_KILL_FOCUS(OnKillFocus)
END_EVENT_TABLE()

ViewPanel3D::ViewPanel3D
	(
		const char* name, wxWindow* parent, wxWindowID id /*= wxID_ANY*/,
		const wxPoint& pos /*= wxDefaultPosition*/, const wxSize& size /*= wxDefaultSize*/, 
		long style /*= wxTAB_TRAVERSAL*/
	) 
	: wxPanel(parent, id, pos, size, style)
{
	mRenderWindowName = wxString( name, gCSConv);
}

const wxString& ViewPanel3D::GetRenderWindowName() const
{
	return mRenderWindowName;
}

void ViewPanel3D::SetViewportBackgroundColour(const wxColour& colour)
{
	float r = colour.Red() / 255.0f;
	float g = colour.Green() / 255.0f;
	float b = colour.Blue() / 255.0f;
	assert(0 && "Not implemented.");
}

wxColour ViewPanel3D::GetViewportBackgroundcolour() const
{
	float r=1.f, g=1.f, b=1.f;
	assert(0);
	wxColour colour(r * 255, g*255, b*255);
	return colour;
}

void ViewPanel3D::OnSize(wxSizeEvent& e)
{
	MainFrame* mainFrame = dynamic_cast<MainFrame*>(GetParent());
	assert(mainFrame);
	mainFrame->OnSize(e);
}

void ViewPanel3D::OnMouse(wxMouseEvent& e)
{
	assert(e.GetEventObject() == this);

	e.Skip();
	e.ResumePropagation(1);
}


void ViewPanel3D::OnKeyDown(wxKeyEvent& e)
{
	assert(e.GetEventObject() == this);
	if (e.GetEventObject() == this)
	{
		e.Skip();
		e.ResumePropagation(1);
	}
}

void ViewPanel3D::OnKeyUp(wxKeyEvent& e)
{
	assert(e.GetEventObject() == this);
	if (e.GetEventObject() == this)
	{
		e.Skip();
		e.ResumePropagation(1);
	}
}

void ViewPanel3D::OnChar(wxKeyEvent& e)
{
	assert(e.GetEventObject() == this);
	if (e.GetEventObject() == this)
	{
		e.Skip();
		e.ResumePropagation(1);
	}
}

void ViewPanel3D::OnSetFocus(wxFocusEvent& e)
{
	//** PLATFORM SPECIFIC CODE	
	if (e.GetEventObject() == this)
	{
		HIMC hIMC;
		hIMC=::ImmGetContext((HWND)GetHWND());
		ImmGetConversionStatus(hIMC,&mConversion,&mSentence);
		if (mConversion & IME_CMODE_NATIVE)
		{
			ImmSetConversionStatus(hIMC, IME_CMODE_ALPHANUMERIC, mSentence);
		}
	}
	e.Skip();
}

void ViewPanel3D::OnKillFocus(wxFocusEvent& e)
{
	//** PLATFORM SPECIFIC CODE	
	if (e.GetEventObject() == this)
	{
		HIMC hIMC;
		hIMC=::ImmGetContext((HWND)GetHWND());
		ImmSetConversionStatus(hIMC, mConversion, mSentence);
	}
	e.Skip();
}